package net.homeip.mmhg.dao;

import java.util.Collection;

import net.homeip.mmhg.domain.Task;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * 
 *
 * @author ilya gerasimov
 */
@Repository
public class TaskDaoImpl implements TaskDao {

	private HibernateTemplate template;

	@Autowired
	public void setHibernateTemplate(SessionFactory sessionFactory) {
		this.template = new HibernateTemplate(sessionFactory);
	}
	
	@Override
	@Transactional(readOnly = true)
	public Task getTask(int id) {
		return (Task) template.get(Task.class, id);
	}

	
	@SuppressWarnings("unchecked")
	@Override
	@Transactional(readOnly = true)
	public Collection<Task> getTasks() {
		return template.findByCriteria(DetachedCriteria.forClass(Task.class));
	}

}
